package com.gzt.bookcatalog.factory;

import com.gzt.bookcatalog.dto.BookRequestDTO;
import com.gzt.bookcatalog.dto.BookResponseDTO;
import com.gzt.bookcatalog.model.Book;
import org.springframework.stereotype.Component;

/**
 * BookFactory 类用于创建 Book 实体和 BookResponseDTO。
 */
@Component
public class BookFactory {

    public static Book createBook(BookRequestDTO bookRequestDTO) {
        return Book.builder()
                .title(bookRequestDTO.getTitle())
                .author(bookRequestDTO.getAuthor())
                .publicationYear(bookRequestDTO.getPublicationYear())
                .isbn(bookRequestDTO.getIsbn())
                .description(bookRequestDTO.getDescription())
                .build();
    }

    public static BookResponseDTO createBookResponseDTO(Book book) {
        return BookResponseDTO.builder()
                .id(book.getId())
                .title(book.getTitle())
                .author(book.getAuthor())
                .publicationYear(book.getPublicationYear())
                .isbn(book.getIsbn())
                .description(book.getDescription())
                .build();
    }
}
